using ASP;
using HoWave.Common;
using HoWave.Web;
using HoWave.Web.Shop.Member;
using System;
using System.Data;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
public class Member_Shop_MytryItem : Member, IRequiresSessionState
{
	public string tag = "all";
	protected Repeater Repeater1;
	protected Label lbPage;
	protected RadioButtonList CommentLevel;
	protected TextBox ContentBox;
	protected HtmlInputHidden GetTryID;
	protected Button ButComment;
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		this.ContentBox.Attributes.Add("onfocus", "onFocus();");
		this.ContentBox.Attributes.Add("onblur", "onblur();");
		this.BindTryProduct();
	}
	public void BindTryProduct()
	{
		CurrPageLinks currPageLinks = new CurrPageLinks();
		int num = 1;
		string text = "";
		if (base.Request.QueryString["pageindex"] != null)
		{
			if (base.Request.QueryString["pageindex"].ToString() != "")
			{
				try
				{
					num = int.Parse(base.Request.QueryString["pageindex"].ToString());
				}
				catch (Exception ex)
				{
					ex.WriteErrorLog(new string[]
					{
						"正常操作"
					});
					num = 1;
				}
			}
		}
		if (base.Request.QueryString["tag"] != null)
		{
			if (base.Request.QueryString["tag"].ToString() != "")
			{
				this.tag = base.Request.QueryString["tag"].ToString();
			}
		}
		if (this.tag == "Success")
		{
			text = " and a.Through=1";
		}
		else
		{
			if (this.tag == "fail")
			{
				text = " and a.Through=-1";
			}
		}
		int pCount = this.conn.ExecuteCount(string.Concat(new object[]
		{
			"select count(*) from HLShop_TryAppcation as a where UserID=",
			base.user.UserID,
			" ",
			text
		}));
		int num2 = (num - 1) * 16;
		DataTable dataTable = this.conn.GetDataTable(string.Concat(new object[]
		{
			"select top 16 a.CreateTime as InputTime, * from HLShop_TryAppcation as a,HLShop_TryProduct as b where a.ApplicationID not in(select top ",
			num2,
			" ApplicationID from HLShop_TryAppcation where UserID=",
			base.user.UserID,
			text,
			" order by CreateTime Desc) and b.TryID=a.ProductID and a.UserID=",
			base.user.UserID,
			" ",
			text,
			" order by b.CreateTime Desc"
		}));
		this.Repeater1.DataSource = dataTable;
		this.Repeater1.DataBind();
		dataTable.Dispose();
		this.lbPage.Text = currPageLinks.CurrPageLink(num, 16, pCount, "个商品", "Shop_TryApplication.aspx?pageindex");
	}
	public string GetStatus(string Through)
	{
		string result = "审核中....";
		if (Through != null && Through != "")
		{
			try
			{
				switch (int.Parse(Through))
				{
				case -1:
					result = "已被决绝";
					break;
				case 1:
					result = "已通过审核";
					break;
				}
			}
			catch (Exception ex)
			{
				ex.WriteErrorLog(new string[0]);
			}
		}
		return result;
	}
	protected void ButComment_Click(object sender, EventArgs e)
	{
		if (this.conn.ExecuteCount(string.Concat(new object[]
		{
			"select count(*) from HLShop_TryComment where UserID=",
			base.user.UserID,
			" and ProductID=",
			int.Parse(this.GetTryID.Value)
		})) > 0)
		{
			this.Page.ClientScript.RegisterStartupScript(base.GetType(), "Test", "<script>alert('你已评论，无需再评论!');</script>");
		}
		else
		{
			int num = 0;
			try
			{
				int num2 = int.Parse(this.GetTryID.Value);
				num = this.conn.Execute(string.Concat(new object[]
				{
					"insert into HLShop_TryComment([UserID],[ProductID],[CreateTime],[Leavel],[Content]) values(",
					base.user.UserID,
					",",
					num2,
					",'",
					DateTime.Now.ToString(),
					"',",
					int.Parse(this.CommentLevel.SelectedValue),
					",'",
					this.ContentBox.Text,
					"')"
				}));
			}
			catch (Exception ex)
			{
				ex.WriteErrorLog(new string[]
				{
					"正常操作"
				});
				num = 0;
			}
			if (num == 1)
			{
				this.Page.ClientScript.RegisterStartupScript(base.GetType(), "Test", "<script>alert('评论成功!');</script>");
			}
			else
			{
				this.Page.ClientScript.RegisterStartupScript(base.GetType(), "Test", "<script>alert('评论失败，请稍后再评论!');</script>");
			}
		}
	}
	public string ShowCommentWriting(string ProductID)
	{
		string result = "";
		int num = this.conn.ExecuteCount("select count(*) from HLShop_TryAppcation where Through=1 and ProductID=" + int.Parse(ProductID));
		if (num > 0)
		{
			result = "评论";
		}
		int num2 = this.conn.ExecuteCount(string.Concat(new object[]
		{
			"select count(*) from HLShop_TryComment where UserID=",
			base.user.UserID,
			" and ProductID=",
			int.Parse(ProductID)
		}));
		if (num2 > 0)
		{
			result = "已评论";
		}
		return result;
	}
	public bool JustDiscountPrice(string ProductID)
	{
		DataTable dataTable = this.conn.GetDataTable("select DiscountPrice from HLShop_TryProduct where TryID=" + int.Parse(ProductID));
		bool result;
		if (dataTable != null && dataTable.Rows.Count > 0)
		{
			if (decimal.Parse(dataTable.Rows[0]["DiscountPrice"].ToString()) <= 0m)
			{
				result = false;
				return result;
			}
		}
		result = true;
		return result;
	}
}
